package com.sunshine.ssm.system;

import com.sunshine.ssm.util.Environment;
import com.sunshine.ssm.util.Prop;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Map;
import java.util.Properties;
import java.util.Set;


/**
 * 系统初始化时加载配置文件
 *
 * @Author: WeiHong
 * @Date: 2017/3/20 14:15
 */
@Component
public class LoadSysConfig {

    private static final Logger LOGGER = LoggerFactory.getLogger(LoadSysConfig.class);

    @PostConstruct
    private void initSystemConfig() {
        LOGGER.info("初始化系统变量,读取 mail.properties 配置文件开始");
        Prop prop = new Prop("mail.properties");
        SysConfig.setHost(prop.get("email.host"));
        SysConfig.setPort(prop.get("email.port"));
        SysConfig.setUserNmae(prop.get("email.username"));
        SysConfig.setPassword(prop.get("email.password"));
        SysConfig.setFrom(prop.get("emial.from"));
        Properties properties = prop.getProperties();
        Set<Map.Entry<Object, Object>> entries = properties.entrySet();
        for (Map.Entry<Object, Object> entry : entries) {
            Environment.put((String) entry.getKey(), (String) entry.getValue());
        }
        LOGGER.info("系统环境变量如下:");
        Environment.logEnv("server environment:", LOGGER);
    }


}
